package server;

import common.Packet;

public class CheckClientThread extends Thread
{
	public void run()
	{
		while(true)
		{
			try
			{
				Thread.sleep(60001);
			} catch (InterruptedException e)
			{
				Server.gui.writeLog("CheckClientThread interrupted");
			}
			Server.gui.writeLog("pinging all clients...");
			//reschedule this for a later time
			//send the messages
			/*for (Client c : Server.clients)
			{
				Server.sendPacket(new Packet(Packet.Type.nw_ping), c.address, c.port);
			}*/
			for(int i = 0; i < Server.clientList.size(); i++) //done in a way to prevent problems with clients being deleted half way through this process (and this method shouldn't be a synchronised method in ClientList as it takes too long and would block everything else)
			{
				server.ClientList.Client c = Server.clientList.get(i);
				if(c != null)
				{
					Server.sendPacket(new Packet(Packet.Type.nw_ping), c.address, c.port);
				}
			}
		}
	}

}
